# I/O processor driver integration Script
# This script loads the complete io driver 
#
# You can specify the connnection between Host and Slave (i2c or usb-serial)
#
# i2c:
# Call with ./io_driver -l -i2c for loading the driver
# Call with ./io_driver -u -i2c for unloading the driver
#
# usb-serial:
# Call with ./io_driver -l -usb-serial for loading the driver
# Call with ./io_driver -u -usb-serial for unloading the driver


if [ "$1" == "-l" ]
then
	#activate Debug output in Linux procfs
	echo "5  3  1  7" >/proc/sys/kernel/printk 
	
	insmod io_communication_driver/io_core.ko
	sleep 1 

	if [ "$2" == "-i2c" ]	
	then
		insmod io_communication_driver/io_com_OVER_I2C.ko
	fi 
	
	if [ "$2" == "-usb-serial" ]	
	then
		# check if ttyUSB file is aviable
		if [ -e "/dev/ttyUSB0" ]		
		then
			insmod io_communication_driver/io_com_OVER_USBSERIAL.ko
		else
			rmmod io_communication_driver/io_core.ko
			echo "ttyUSB0 File is not aviable...please reconnect your usb-serial adapter."			
			exit 1
		fi
	
	fi 
	insmod io_i2c_interface/io_i2c.ko
	insmod io_gpio_interface/io_gpio.ko



elif [ "$1" == "-u" ]
then 
	rmmod io_i2c_interface/io_i2c.ko
	sleep 1
	rmmod io_gpio_interface/io_gpio.ko
	sleep 2

	if [ "$2" == "-i2c" ]	
	then
		rmmod io_communication_driver/io_com_OVER_I2C.ko
	fi 
	
	if [ "$2" == "-usb-serial" ]	
	then
		rmmod io_communication_driver/io_com_OVER_USBSERIAL.ko
	fi 

	#sleep 1
	rmmod io_core.ko
fi


